package com.edu.robot.modules.robot.corvert;

import cn.hutool.core.date.DateUtil;
import com.edu.robot.modules.robot.controller.vo.ModelConfigVO;
import com.edu.robot.modules.robot.dto.ModelConfigDTO;
import com.edu.robot.modules.robot.model.CrModelConfig;

import java.util.Optional;

/**
 * @program: KQAIA
 * @description:
 * @author: 无恙
 * @create: 2025-03-23 19:11
 **/


public class ModelConfigCovert {
	public static ModelConfigDTO covert(CrModelConfig crModelConfig){
		ModelConfigDTO modelConfigDTO = new ModelConfigDTO();
		modelConfigDTO.setId(crModelConfig.getId());
		modelConfigDTO.setModelName(crModelConfig.getModelName());
		modelConfigDTO.setTopK(crModelConfig.getTopK());
		modelConfigDTO.setTopP(crModelConfig.getTopP());
		modelConfigDTO.setTemperature(crModelConfig.getTemperature());
		modelConfigDTO.setExtInfo(crModelConfig.getExtInfo());
		modelConfigDTO.setStopWords(crModelConfig.getStopWords());
		modelConfigDTO.setCreateAt(DateUtil.format(crModelConfig.getCreatedAt(), "yyyy-MM-dd"));
		return modelConfigDTO;
	}

	public static CrModelConfig covert(ModelConfigDTO modelConfigDTO){
		CrModelConfig crModelConfig = new CrModelConfig();
		crModelConfig.setModelName(modelConfigDTO.getModelName());
		crModelConfig.setTopK(modelConfigDTO.getTopK());
		crModelConfig.setTopP(modelConfigDTO.getTopP());
		crModelConfig.setTemperature(modelConfigDTO.getTemperature());
		crModelConfig.setStopWords(modelConfigDTO.getStopWords());
		crModelConfig.setExtInfo(modelConfigDTO.getExtInfo());
		return crModelConfig;
	}

	public static ModelConfigDTO covert(ModelConfigVO modelConfigVO){
		ModelConfigDTO modelConfigDTO = new ModelConfigDTO();
		modelConfigDTO.setModelName(modelConfigVO.getModelName());
		Optional.ofNullable(modelConfigVO.getTopK()).ifPresent(k -> modelConfigDTO.setTopK(Integer.valueOf(k)));
		Optional.ofNullable(modelConfigVO.getTopP()).ifPresent(p -> modelConfigDTO.setTopP(Double.valueOf(p)));
		Optional.ofNullable(modelConfigVO.getTemperature()).ifPresent(t -> modelConfigDTO.setTemperature(Float.valueOf(t)));
		modelConfigDTO.setExtInfo(modelConfigVO.getExtInfo());
		modelConfigDTO.setStopWords(modelConfigVO.getStopWords());
		return modelConfigDTO;

	}

	public static CrModelConfig covertToDO(ModelConfigVO modelConfigVO){
		CrModelConfig crModelConfig = new CrModelConfig();
		Optional.ofNullable(modelConfigVO.getId()).ifPresent(id-> crModelConfig.setId(Long.valueOf(id)));
		Optional.ofNullable(modelConfigVO.getModelName()).ifPresent(crModelConfig::setModelName);
		Optional.ofNullable(modelConfigVO.getTopK()).ifPresent(k -> crModelConfig.setTopK(Integer.valueOf(k)));
		Optional.ofNullable(modelConfigVO.getTopP()).ifPresent(p -> crModelConfig.setTopP(Double.valueOf(p)));
		Optional.ofNullable(modelConfigVO.getTemperature()).ifPresent(t-> crModelConfig.setTemperature(Float.valueOf(t)));
		crModelConfig.setExtInfo(modelConfigVO.getExtInfo());
		crModelConfig.setStopWords(modelConfigVO.getStopWords());
		return crModelConfig;
	}
}
